package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.sgb.capital.base.BaseRecycleAdapter;
import com.sgb.capital.utils.ItemViewHolder;
import com.sgb.capital.utils.ResolutionUtil;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemHomeMenuViewBinding;
import com.swgk.core.view.entity.HomeManageMenuEntity;

import java.util.List;

public class HomeMenuAdapter extends BaseRecycleAdapter<List<HomeManageMenuEntity>> {

    public HomeMenuAdapter(Context context, List<List<HomeManageMenuEntity>> data) {
        super(context, R.layout.item_home_menu_view, data);
    }

    @Override
    public void convert(ItemViewHolder holder, List<HomeManageMenuEntity> list) {
        ItemHomeMenuViewBinding binding = (ItemHomeMenuViewBinding) holder.getmBinding();
        if (list.size() >= 1)
            Glide.with(context).load(list.get(0).getIconUrl()).into(binding.ivImage1);
        if (list.size() >= 2)
            Glide.with(context).load(list.get(1).getIconUrl()).into(binding.ivImage2);
        if (list.size() >= 3)
            Glide.with(context).load(list.get(2).getIconUrl()).into(binding.ivImage3);
        if (true){
            binding.ivImage4.setVisibility(View.GONE);
        }
        if (list.size() >= 4)
            Glide.with(context).load(list.get(3).getIconUrl()).into(binding.ivImage4);

        ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
        params.width = ResolutionUtil.getScreenWidth(context) / 5;

        binding.ivImage1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onMenuClick(list.get(0));
            }
        });
        binding.ivImage2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onMenuClick(list.get(1));
            }
        });
        binding.ivImage3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onMenuClick(list.get(2));
            }
        });
        binding.ivImage4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onMenuClick(list.get(3));
            }
        });
    }

    public interface HomeMenuClickListener {

        void onMenuClick(HomeManageMenuEntity entity);
    }

    private HomeMenuClickListener listener;

    public void setListener(HomeMenuClickListener listener) {
        this.listener = listener;
    }
}
